<template>
	<view class="page">
		
		<view class="g-tips">
			<view>可寄存额度：<text>{{ableKeep_account||0}}</text></view>
		</view>
		<view class="g-item">
        	<text class="name">转入寄存</text>
        	<view class="g-info g-price">
				<input type="number" placeholder="请输入转入数量" placeholder-style="color:#cecccf" v-model="postData.deposit_money">
			</view>
        </view>
		<view class="g-item" @tap="directionToggle('type')">
			<text class="name">选择账户</text>
			<view class="g-info g-type">
				<picker @change="bindMultiPickerChange_account" :value="accountIndex" :range="accountArray">
					<view class="uni-input">{{accountArray[accountIndex]}}</view>
				</picker>
			</view>
			<view class="arrow"><arrow size="28" color="#656565" :direction="directionType?'bottom':'right'"></arrow></view>
		</view>
		<view class="g-item" @tap="directionToggle('date')">
			<text class="name">寄存期限</text>
			<view class="g-info g-type">
				<picker @change="bindMultiPickerChange_date" :value="dateIndex" :range="dateArray" range-key="month_text">
					<view class="uni-input">{{dateText}}</view>
				</picker>
			</view>
			<view class="arrow"><arrow size="28" color="#656565" :direction="directionDate?'bottom':'right'"></arrow></view>
		</view>
		<view class="g-rules" v-if="rulesData != ''||rulesData">
			<view class="title">规则：</view>
			<uParse :content="rulesData"></uParse>
		</view>
		
        <button class="u-finish" @tap="togglePopup()">提 交</button>
		<view class="g-frame-mask" v-if="showPopup"></view>
		<view class="g-frame" v-if="showPopup">
			<view class="m-frame-header">
			    <view class="u-frame-title">确认申请</view>
			    <image class="u-frame-close" src="../../../static/icons/ydt/close.png" mode="widthFix" @tap="togglePopup"></image>
			</view>
			<view class="u-frame-cont">
				<view><text class="text">寄存期限：</text><text>{{dateArray[dateIndex]['month_text']}}</text></view>
				<view><text class="text">账号类型：</text><text>{{accountArray[accountIndex]}}</text></view>
				<view><text class="text">转入寄存：</text><text>{{postData.deposit_money}}</text></view>
			</view>
			<view class="m-frame-footer">
			    <view class="u-reset" @tap="togglePopup()">取消</view>
			    <view class="u-confirm" @tap="confirm">确定</view>
			</view>
			
		</view>
		<view class="m-loading" v-if="isShowLoading">
		    <image src="../../../static/images/loading.gif" mode="widthFix"></image>
		    <text>加载中</text>
		</view>
	</view>
</template>

<script>
	
	import jewel from '@/common/common_zb.js';
	import uParse from '@/components/uParse/src/wxParse.vue';
	export default {
		data() {
			return {
                dateArray: [],
				dateIndex: 0,
				accountArray: [],
				accountIndex: 0,
				sBankType: '',
				isShowLoading: false,
				account: '',
				freePrice:'',
				showPopup: false,
				ableKeep_account: 0,
				postData:{
					deposit_id:1,
					deposit_money:0,
					account_type:''
				},
				accountKey:[],
				rulesData:'',
				directionType: false,
				directionDate:false,
				dateText:''
			};
		},
		components: {
			uParse
		},
        methods: {
			togglePopup() {
				uni.hideKeyboard();
			    this.showPopup = !this.showPopup;
			},
			confirm() {
				let that = this
				that.isShowLoading = true
				jewel.get('agent_jewel/deposit_order',that.postData,true,function(res){
					that.isShowLoading = false
					if(res.data.code == 0){
						jewel.showToast(res.data.msg,1000)
						setTimeout(()=>{
							uni.navigateTo({
								url:'/pages/jewel/order/orderlist?tarBarType=5'
							})
						},1000)
					}else{
						jewel.showToast(res.data.msg)
					}
					that.togglePopup();
				})
			},
			//寄存时间
			bindMultiPickerChange_date(e){
				let that = this
				that.dateIndex = e.detail.value||e.target.value
				that.postData.deposit_id = that.dateArray[that.dateIndex]['id']
				that.dateText = that.dateArray[that.dateIndex]['month_text']
				that.directionDate = false
			},
			//寄存账户
			bindMultiPickerChange_account(e){
				let that = this
				that.accountIndex = e.detail.value||e.target.value
				that.postData.account_type = that.accountKey[that.accountIndex]
				that.ableKeep_account = that.agentInfo[that.accountKey[that.accountIndex]][0]
				that.directionType = false
			},
			directionToggle(type){
				if(type=='type'){
					this.directionType = true
				}else{
					this.directionDate = true
				}
				
			}
        },
		onShow() {
			let that = this
			jewel.get('agent_jewel/deposit_info',{},true,function(res){
				//可寄存额度原数据
				that.agentInfo = res.data.agent
				//选择框
				that.accountArray = Object.values(res.data.accout_type)
				//寄存时间
				that.dateArray = res.data.deposit_type
				that.rulesData =  res.data.rules
				for(let i in that.agentInfo){
					that.accountKey.push(i)
				}
				that.ableKeep_account = that.agentInfo[that.accountKey[0]][0]
				that.postData.account_type = that.accountKey[0]
				that.dateIndex = that.accountIndex = 0
				that.dateText = that.dateArray[that.dateIndex]['month_text']
			})
			that.rulesData = '规则'
		}
	}
</script>


<style>
	.page{
		background: #f5f5f5;
	}
	.g-item{
		display: flex;
		justify-content: flex-start;
		align-items: center;
		height: 91rpx;
		background: #ffffff;
		margin-bottom: 19rpx;
		padding: 0 27rpx;
		position: relative;
	}
	.loan_border{
		width: 100%;
		border: 0;
	}
	.selected {
	    background: #d71611;
	    color: #fff;
	}
	.loan_stuff{
		padding: 0 10rpx;
		height: 62rpx;
		text-align: center;
		line-height: 62rpx;
		border-radius: 8rpx;
		font-size: 32rpx;
		margin-right: 16rpx;
	}
	.g-item .name{
		width: 120rpx;
	}
    .g-type picker {
        flex: 1;
        position: relative;
        z-index: 2;
        color: #000000;
		text-align: left;
    }
	.g-tips{
		color: #6f6f6f;
		font-size: 26rpx;
		padding: 0 27rpx;
		line-height: 100rpx;
	}
	.g-tips text{
		color: #d71611;
	}
	.g-info{
		margin-left: 50rpx;
		position: relative;
		display: flex;
		align-items: center;
		width: 67%;
		position: relative;
	}
	.g-info .icon{
		color: #272727;
		font-size: 30rpx;
		line-height: 91rpx;
		margin-right: 10rpx;
	}
	.g-info.g-price{
		display: flex;
		flex: 1;
		justify-content: left;
		align-items: center;
	}
	.g-price input{
		flex: 1;
	}
	.g-info .arrow{
		position: absolute;
		right: 10rpx;
		top: 50%;
		transform: translateY(-50%);
	}
    .u-finish {
        width: 90%;
        margin:50rpx auto;
        background: #d71611;
        color: #fff;
        padding: 12px 0;
        border-radius: 100px;
        box-shadow: 0 0 10px rgba(0,0,0,.2);
    }
	.g-frame {
	    width: 581rpx;
	    background: #fff;
	    border-radius: 20rpx;
	    position: fixed;
	    top: 50%;
	    overflow: hidden;
	    left: 50%;
		/* margin-top: -215rpx; */
		/* margin-left: -290rpx; */
		z-index: 12;
		transform: translate(-50%,-50%);
	}
	
	.g-frame-mask {
	    background: #000;
	    opacity: .5;
	    height: 100vh;
	    width: 100%;
	    position: fixed;
	    top: 0rpx;
		z-index: 11;
	}
	
	.m-frame-header {
	    height: 110rpx;
	    width: 100%;
	    background: #d71311;
	    border-top-right-radius: 20rpx;
	    border-top-left-radius: 20rpx;
		position: relative;
		margin-bottom: 35rpx;
	}
	.u-frame-title {
	    width: 100%;
	    text-align: center;
	    color: #fff;
	    line-height: 110rpx;
	    font-size: 32rpx;
	}
	
	.u-frame-close {
	    width: 42rpx;
	    height: 42rpx;
	    background-size: 100%;
	    position: absolute;
	    top: 50%;
		margin-top: -21rpx;
	    right: 32rpx;
	}
	.u-frame-cont{
		text-align: center;
		font-size: 36rpx;
		padding-bottom: 35rpx;
		line-height: 60rpx;
		width: 500rpx;
		margin: 0 auto;
	}
	.u-frame-cont view{
		display: flex;
		width: 80%;
		margin: 0 auto;
		justify-content: flex-start;
	}
	.m-frame-footer {
	    height: 100rpx;
	    width: 100%;
	    box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
		display: flex;
		align-items: center;
		margin-top: 20rpx;
	}
	
	.m-frame-footer view {
		flex: 1;
	    line-height: 100rpx;
	    text-align: center;
	    font-size: 32rpx;
	}
	
	.u-reset {
	    color: #ff0000;
	    background: #fff;
	}
	
	.u-confirm {
	    background: #d71311;
	    color: #fff;
	    border-bottom-right-radius: 16rpx;
	}
	.u-tips-phone {
		padding: 20rpx;
	}
	.u-get-code {
	    border-radius: 4px;
	    color: #fff;
	    background: #f7ba43;
	    padding: 12rpx 16rpx;
	    position: absolute;
	    z-index: 3;
		right: 0;
		top: 50%;
		transform: translateY(-50%);
	}
	.g-rules{
		padding: 0 27rpx;
		margin-bottom: 50rpx;
		padding-bottom: 50rpx;
	}
	.g-rules .title{
		color: #6f6f6f;
		font-size: 26rpx;
	}
</style>